<?php defined('SYSPATH') or die('No direct script access.');

class Model_Admin_Shop
{
	
	public function setCategory($name)
	{
		$category = ORM::factory('shopcategory');
		
		$category->id	= "";
		$category->name	= $name;
		$category->save();
		
		return true;
	}
	
	
	public function getCategorys()
	{
		$categorys = ORM::factory('shopcategory')->find_all();
		
		$i = 0;
		foreach($categorys as $k => $v)
		{
			$array[$i]['id']	= $v->id;
			$array[$i]['name']	= $v->name;
			$i++;
		}
		
		return $array;
	}
	
	public function updateCategory($id, $name)
	{
	
		$category = ORM::factory('shopcategory')->where('id', '=', $id)->find();
		
		$category->name	= $name;
		$category->update();
		
		return true;
	}

	
	public function getProducts()
	{
		$shopproducts = ORM::factory('shopproduct')->find_all();
		
		$i = 0;
		foreach($shopproducts as $k => $v)
		{
			$array[$i]['id']	= $v->id;
			$array[$i]['name']	= $v->name;
			$array[$i]['description']	= $v->photo;
			$array[$i]['price']	= $v->price;
			$i++;
		}
		
		return $array;
	}
	
	
	
	public function getAllShoping()
	{
		$array = array();
		
		$orders = ORM::factory('shoporder')
			->order_by('id', 'desc')
			->find_all();
		
		$i = 0;
		foreach($orders as $k => $v)
		{
			$array[$i]['id']	= $v->id;
			$array[$i]['userId']	= $v->userId;
			$array[$i]['price']	= $v->price;
			$array[$i]['date']	= $v->date;
			$array[$i]['status']	= $v->status;
			$i++;
		}
		
		return $array;
	}
	
	
	public function getNewShoping()
	{
		$array = array();
		
		$orders = ORM::factory('shoporder')
			->where('status', '=', 'Unpaid')
			->order_by('id', 'desc')
			->find_all();
		
		$i = 0;
		foreach($orders as $k => $v)
		{
			$array[$i]['id']	= $v->id;
			$array[$i]['userId']	= $v->userId;
			$array[$i]['price']	= $v->price;
			$array[$i]['date']	= $v->date;
			$array[$i]['status']	= $v->status;
			$i++;
		}
		
		return $array;
	}
	
	
	public function getOldShoping()
	{
		$array = array();
		
		$orders = ORM::factory('shoporder')
			->where('status', '=', 'Paid')
			->order_by('id', 'desc')
			->find_all();
		
		$i = 0;
		foreach($orders as $k => $v)
		{
			$array[$i]['id']	= $v->id;
			$array[$i]['userId']	= $v->userId;
			$array[$i]['price']	= $v->price;
			$array[$i]['date']	= $v->date;
			$array[$i]['status']	= $v->status;
			
			$i++;
		}
		
		
		return $array;
	}
	
	
} // End Shop
